<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% if action == 'new' %}新建日记{% else %}编辑日记{% endif %} - 个人日记应用</title>
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
    <div class="container">
        <header>
            <h1>个人日记应用</h1>
            <p>记录生活的点滴</p>
        </header>
        
        <!-- 消息提示区域 -->
        {% with messages = get_flashed_messages() %}
            {% if messages %}
                <div class="flash-messages">
                    {% for message in messages %}
                        <div class="flash-message">
                            {{ message }}
                        </div>
                    {% endfor %}
                </div>
            {% endif %}
        {% endwith %}
        
        <!-- 编辑日记表单 -->
        <div class="edit-container">
            <h2>{% if action == 'new' %}新建日记{% else %}编辑日记{% endif %}</h2>
            <form method="post" action="{% if action == 'new' %}/new{% else %}/edit/{{ entry[0] }}{% endif %}">
                <div class="form-group">
                    <label for="title">标题</label>
                    <input type="text" id="title" name="title" placeholder="输入日记标题" value="{{ entry[1] if entry else '' }}" required>
                </div>
                
                <div class="form-group">
                    <label for="content">内容</label>
                    <textarea id="content" name="content" placeholder="开始记录你的想法..." rows="15" required>{{ entry[2] if entry else '' }}</textarea>
                </div>
                
                {% if entry %}
                <div class="entry-info">
                    <p><strong>创建时间:</strong> {{ entry[3] }}</p>
                    {% if entry[3] != entry[4] %}
                        <p><strong>更新时间:</strong> {{ entry[4] }}</p>
                    {% endif %}
                </div>
                {% endif %}
                
                <div class="form-actions">
                    <button type="submit" class="save-btn">保存日记</button>
                    <a href="/" class="cancel-btn">取消</a>
                </div>
            </form>
        </div>
    </div>
</body>
</html>